package com.newcoretech.platform_service

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import io.flutter.plugin.common.MethodChannel


//商米pda 通知
const val SUNMI_ACTION = "com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED"

//祥承PDA
const val KOZEN_ACTION = "com.xcheng.scanner.action.BARCODE_DECODING_BROADCAST"

//按键pda 通知，在MainActivity dispatchKeyEvent中控制
const val KEYINPUT_PDA_SCAN_ACTION = "keyinput.pda.scan.action"

//君安宏图/蓝畅 PDA
const val JAHT_ACTION = "scan.rcv.message"

//盈达(iData)PDA
const val YD_ACTION = "android.intent.action.SCANRESULT"

//艾迪斑马PDA
const val EDDIE_ZEBRA_ACTION = "com.eddie.scanner.DATA"

//新核云斑马PDA
const val NEWCORE_ZEBRA_ACTION = "com.newcoretech.scanner.DATA"

//优博讯
const val URONO_ACTION = "android.intent.ACTION_DECODE_DATA"

class PDABroadcastReceiver(private val methodChannel: MethodChannel) : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent?.action == SUNMI_ACTION) {
            val code = intent.getStringExtra("data")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if (intent?.action == KOZEN_ACTION) {
            val code = intent.getStringExtra("EXTRA_BARCODE_DECODING_DATA")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == KEYINPUT_PDA_SCAN_ACTION) {
            val code = intent.getStringExtra("data")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == JAHT_ACTION) {
            val broadCode: ByteArray? = intent.getByteArrayExtra("barocode")
            val code = broadCode?.let { String(it) }
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == YD_ACTION) {
            val code = intent.getStringExtra("value")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == EDDIE_ZEBRA_ACTION) {
            val code = intent.getStringExtra("com.symbol.datawedge.data_string")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == NEWCORE_ZEBRA_ACTION) {
            val code = intent.getStringExtra("com.symbol.datawedge.data_string")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        } else if(intent?.action == URONO_ACTION) {
            val code = intent.getStringExtra("barcode_string")
            methodChannel.invokeMethod("onPDAScanResult",mapOf("result" to code))
        }
    }

}
